import { ADDRESS_LIST,GET_PROVINCE_LIST} from "./actionsTypes";
export const addressList = data => ({type: ADDRESS_LIST, data: data});//地址列表
export const getProvinceList = data => ({type: GET_PROVINCE_LIST, data: data});

import getAddAddressService from '../services/addAddressService';
import {Toast} from 'antd-mobile'

export const getAddAddress=(data,callBack)=>{
	return (dispatch, getState)=> {
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getAddAddressService.region(data).then(resultData => {
			Toast.hide();
			if (resultData.code == 1000) {

				dispatch(getProvinceList(resultData.body.areaMsgList))
				callBack&&callBack(resultData.body.areaMsgList)
			} else {
				Toast.info(resultData.msg);
			}
		},()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		});
	}
}

export const address=(data,callBack)=>{
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getAddAddressService.region(data).then(resultData => {
			Toast.hide();
			if (resultData.code == 1000) {
				callBack&&callBack(resultData.body.areaMsgList)
			} else {
				Toast.info(resultData.msg);
			}
		},()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		});

}

export const setAddAddress=(data,callBack)=>{
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getAddAddressService.addAddress(data).then(resultData => {
			Toast.hide();
			if (resultData.code == 1000) {
				callBack()
			} else {
				Toast.info(resultData.msg);
			}
		},()=>{
			Toast.hide(); 
            Toast.info("系统繁忙，请稍后再试");
		});
}
